package testJpa;

import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.Id;
import javax.persistence.PersistenceContext;
import javax.persistence.Transient;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
import org.hibernate.validator.Length;

@Entity
@Indexed
public class User
{
    @Transient
    @PersistenceContext(unitName = "testJpa")
    private static EntityManager entityManager;

    @Id
    @DocumentId
    private long id;

    @Length(max=20)
    private String name;
    
    @Field(index=Index.TOKENIZED, store=Store.NO)
    private String description1;
    
    private String description2;
    
    @Field(index=Index.TOKENIZED, store=Store.NO)
    private String description3;

    public String toString(){
    	return id + " " + name + " " + description1 + " " + description2 + " " + description3;
    }
    
    public static User find(long id)
    {
        return entityManager.find(User.class, new Long(id));
    }

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public static EntityManager getEntityManager()
    {
        return entityManager;
    }

    public static void setEntityManager(EntityManager entityManager)
    {
        User.entityManager = entityManager;
    }

	public String getDescription1() {
		return description1;
	}

	public void setDescription1(String description1) {
		this.description1 = description1;
	}

	public String getDescription2() {
		return description2;
	}

	public void setDescription2(String description2) {
		this.description2 = description2;
	}

	public String getDescription3() {
		return description3;
	}

	public void setDescription3(String description3) {
		this.description3 = description3;
	}
}
